﻿Imports QLPhuTungOto.Data
Imports QLPhuTungOto.Bus
Imports DevExpress.XtraCharts


Public Class ucThongKeDoanThuLoiNhuan
    Dim hdBUS As New HoaDonBUS
    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub
    Private Sub LoadThongKe()
        Dim a As Date = dnNgay.DateTime
        Dim s As String = "Thống kê doanh thu tháng "
        Dim diagram As XYDiagram = TryCast(ChartControl1.Diagram, XYDiagram)
        Dim diagram1 As XYDiagram = TryCast(ChartControl2.Diagram, XYDiagram)

        'Load danh sách thống kê theo ngày và tháng
        gcNgay.DataSource = hdBUS.ThongKeDoanhThu(a)
        gvNgay.ViewCaption = "Tháng " + a.Month.ToString()
        gcThang.DataSource = hdBUS.ThongKeDoanhThu2(a)
        gvThang.ViewCaption = "Năm " + a.Year.ToString()

        'Load chart thống kê theo tháng
        ChartControl1.Titles(0).Visible = True
        ChartControl1.Titles(0).Text = s + a.Month.ToString() + "/" + a.Year.ToString()
        'diagram.AxisX.DateTimeGridAlignment = DateTimeMeasurementUnit.Day
        'diagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day
        'diagram.AxisX.DateTimeOptions.Format = DateTimeFormat.Custom
        'diagram.AxisX.DateTimeOptions.FormatString = "dd"
        diagram.AxisY.NumericOptions.Format = NumericFormat.Currency
        ChartControl1.DataSource = hdBUS.ThongKeDoanhThu(a)

        'Load chart thống kê theo năm
        s = "Thống kê doanh thu năm "
        ChartControl2.Titles(0).Visible = True
        ChartControl2.Titles(0).Text = s + a.Year.ToString()
        diagram1.AxisY.NumericOptions.Format = NumericFormat.Currency
        ChartControl2.DataSource = hdBUS.ThongKeDoanhThu2(a)


    End Sub
    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
        LoadThongKe()
    End Sub


    Private Sub ucThongKeDoanThuLoiNhuan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadThongKe()
    End Sub

    Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInThang.Click
        Dim rp As New XtraReport1
        Dim a As DateTime = dnNgay.DateTime
        rp.DataSource = hdBUS.ThongKeDoanhThu(a)
        rp.Parameters(0).Value = a.ToString("MM/yyyy")
        rp.CreateDocument()
        rp.ShowPreview()
    End Sub

    Private Sub SimpleButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInNam.Click
        Dim rp As New XtraReport2
        Dim a As DateTime = dnNgay.DateTime
        rp.DataSource = hdBUS.ThongKeDoanhThu2(a)
        rp.Parameters(0).Value = a.ToString("yyyy")
        rp.CreateDocument()
        rp.ShowPreview()
    End Sub
End Class
